/* eslint-disable max-len */
import React, {
  createContext, useContext, useState, useMemo,
} from 'react';
import {
  DataSet,
} from 'choerodon-ui/pro';
import templateSaveDataSet from './templateSaveDataSet';

const Store = createContext({} as any);

export function useTemplateSaveStore() {
  return useContext(Store);
}

export const StoreProvider = (props: any) => {
  const {
    children,
    level,
  } = props;

  const prefix = 'c7ncd-template-save' as const;

  const TemplateSaveDs = useMemo(() => new DataSet(templateSaveDataSet(level)), []);

  const value = {
    ...props,
    TemplateSaveDs,
    prefix,
  };
  return (
    <Store.Provider value={value}>
      {children}
    </Store.Provider>
  );
};
